<?php

namespace app\admin\model\scanwork;

use think\Model;

class CustomField extends Model
{
    protected $name = 'scanwork_custom_field';
    
    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    protected $append = [
        'module_name_text',
        'field_type_text',
        'status_text'
    ];

    public function getModuleNameList()
    {
        return [
            'order' => '订单',
            'product' => '产品',
            'process' => '工序',
            'resource' => '资源',
            'equipment' => '设备',
            'employee' => '员工'
        ];
    }

    public function getFieldTypeList()
    {
        return [
            'text' => '文本',
            'number' => '数字',
            'date' => '日期',
            'datetime' => '日期时间',
            'select' => '下拉选择',
            'textarea' => '多行文本',
            'checkbox' => '复选框',
            'radio' => '单选框'
        ];
    }

    public function getStatusList()
    {
        return [
            'normal' => '正常',
            'hidden' => '隐藏'
        ];
    }

    public function getModuleNameTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['module_name']) ? $data['module_name'] : '');
        $list = $this->getModuleNameList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getFieldTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['field_type']) ? $data['field_type'] : '');
        $list = $this->getFieldTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
}

